#include<iostream>
#include<queue>
using namespace std;
typedef long long LL;
int n;
void bfs(int n)
{
	queue<LL>q;
	q.push(1);
	while (q.size()) {
		LL t = q.front();
		q.pop();
		if (t % n == 0) {
			cout << t << endl;
			return;
		}
		q.push(t * 10);
		q.push(t * 10 + 1);
	}
}
int main()
{
	while (cin >> n, n) {
		bfs(n);
	}
	return 0;
}